<? if ($this->user->checkRight(1)): ?>
	<a href="/admin/articles/add">Добавить запись в блог</a>
<? endif; ?>

<? if ($this->user->checkRight(2)): ?>
	<? if (isset($deleted)): ?>
		| <a href="/admin/articles/">Все записи</a>
	<? else: ?>
		| <a href="/admin/articles/deleted">Удаленные записи</a>
	<? endif; ?>
<? endif; ?>

<? if ($pages) :
	$colspan = ($this->user->checkRight(2) && empty($deleted))?8:6;
?>
	<table>
	<tr>
		<th>Блог</th>
		<th>id</th>
		<th>Название</th>
		<th>Последнее обновление</th>
		<th>Автор</th>
		<? if($this->user->checkRight(2)): ?>
		<th></th>
		<th></th>
		<th></th>
		<? endif; ?>
	</tr>
	<?
		$pre = 0;
		foreach ($pages as $page) :
			if ($pre!=$page->tBlog && isset($blogs[$page->tBlog]))
			{?>
			<tr>
			<td colspan="<?=$colspan?>" style="font-weight:bold; background-color:#ddd; padding:5px;">
				<? if ($this->user->checkRight(2)): ?>
					<a href="/admin/pages/add/<?=$page->tBlog?>"><?=$blogs[$page->tBlog]->pName?></a>
				<? else:
					echo $blogs[$page->tBlog]->pName;
				endif; ?>
			</td>
			</tr>
			<? $pre = $page->tBlog;
			}
		?>
		<tr>
			<td></td>
			<td>
				<?=$page->id?>
			</td>
			<td>
				<? if ($this->user->checkRight(2) || $this->user->id == $page->tUserCreated):?>
					<a style="margin-left:20px;" href="/admin/articles/add/<?=$page->id?>"><?=$page->pName?></a>
				<? elseif ($this->user->checkRight(8)): ?>
					<a style="margin-left:20px;" href="/<?=$blogs[$page->tBlog]->pUrl?>/<?=$page->pUrl?>"><?=$page->pName?></a>
				<? else:
					echo $page->pName;
				endif; ?>
			</td>
			<td>
				<?=printDate(($page->dUpdated)?$page->dUpdated:$page->dCreated, true)?>
			</td>
			<td>
				<?=$users[$page->tUserCreated]?>
			</td>
			<? if ($this->user->checkRight(2)): ?>

				<? if (empty($deleted)): ?>
					<td><?=($page->dAllowed)?'':'<span data-manage="1" data-art="'.$page->id.'" class="linkStyled manageButton">Утвердить</span>'?></td>
					<td><?=($page->dAllowed)?'<span data-manage="0" data-art="'.$page->id.'" class="linkStyled manageButton">Разутвердить</span>':''?></td>
				<? endif; ?>
				
				<td><?=($page->dDeleted)?
					'<span data-manage="3" data-art="'.$page->id.'" class="linkStyled manageButton">Восстановить</span>':
					'<span data-manage="2" data-art="'.$page->id.'" class="linkStyled manageButton">Удалить</span>'?>
				</td>
			<? else: ?>
				<td><?=($page->dAllowed)?'Утверждено':''?></td>
			<? endif; ?>
		</tr>
	<?	endforeach; ?>
	</table>
<? else: ?>
	Пока что ни одной статьи нет.
<? endif; ?>